<?php 
	class DB {		
		public $dbh;

		function __construct(){	
			try {
				$this->dbh = new PDO("mysql:host=127.0.0.1;dbname=8bitstock",'root','');		
			}
			catch(PDOException $e) {
				echo $e->getMessage();
			}
		}
		
		function query($sql){					
			$query = $this->dbh->query($sql);
			if(is_object($query)) {
				$res = $query->fetchAll(PDO::FETCH_ASSOC);				
			}
			else {
				$res = $query;
			}	
			return $res;	
		}

		function insert($sql){			
			$res = $this->dbh->exec($sql);			
			return ($res !== false ? $this->dbh->lastInsertId() : false);		
		}

		function update($sql){
			$res = $this->dbh->exec($sql);
			return $res;
		}

		function delete($sql){
			$res = $this->dbh->exec($sql);
			return $res;
		}

		function getErrorMsg(){
			$e = $this->dbh->errorInfo();
			return $e[2];
		}

		function beginTransaction(){
			 $this->dbh->beginTransaction();
		}

		function commit(){
			 $this->dbh->commit();
		}

		function rollback(){
			 $this->dbh->rollBack();
		}
	}			
?>